package leetcode.code0110;

import leetcode.IDebug;
import leetcode.helper.tree.TreeNode;

public class Solution111 implements IDebug {

	public int minDepth(TreeNode root) {
		if (root == null)
			return 0;
		// 空节点返回大值 , 左右节点只有一个大值 , 比较的时候会被甩掉 , 两个大值说明当前是叶子返回1
		int left = root.left != null ? this.minDepth(root.left) : Integer.MAX_VALUE;
		int right = root.right != null ? this.minDepth(root.right) : Integer.MAX_VALUE;
		// 最后一个节点会返回1,每次向上+1
		return Math.min(left, right) == Integer.MAX_VALUE ? 1 : Math.min(left, right) + 1;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
